package com.feit.springcloudclient.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.feit.springcloudclient.mapper.UserMapper;
import com.feit.springcloudclient.pojo.User;
import com.feit.springcloudclient.service.IUserService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author zhaiding
 * @date 2019/3/14 14:51
 */
@Service(value = "userService")
public class UserServiceImpl implements IUserService {

    @Resource
    private UserMapper userMapper;

    @Override
    public User queryById(Integer id) {
        return userMapper.selectById(id);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int updateById(User user) {
        return userMapper.updateById(user);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int deleteById(Integer id) {
        return userMapper.deleteById(id);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int save(User user) {
        return userMapper.insert(user);
    }

    @Override
    public List<User> queryAll() {
        return userMapper.selectList(new QueryWrapper<>());
    }
}
